Skip to content

Conversation

@krystophny
Copy link
Collaborator

Summary

Fixes PDF scale regression where plots appeared smaller with centering instead of filling the available plot area. This regression was introduced ~2 weeks ago when aspect ratio preservation was added to PDF coordinate transformations.

Root Cause

The regression was introduced in commit 1c2fdea when aspect ratio preservation logic was added to normalize_to_pdf_coords():

  • Before: Used independent X/Y scales → plots filled available area
  • After: Used common_scale = min(x_scale, y_scale) → smaller plots with centering

Technical Fix

Restored independent axis scaling in PDF coordinate transformations:

Modified Functions

  • normalize_to_pdf_coords(): Removed common scale, use separate x_scale/y_scale
  • safe_coordinate_transform(): Removed aspect ratio preservation logic

Key Changes

! OLD (with aspect ratio preservation)
common_scale = min(x_scale, y_scale)
pdf_x = (x - ctx%x_min) * common_scale + plot_left + x_offset

! NEW (independent scaling - restored)  
x_scale = plot_width / x_range
y_scale = plot_height / y_range
pdf_x = (x - ctx%x_min) * x_scale + plot_left

Validation

  • Regression Test: Created test_pdf_scale_regression.f90 demonstrating issue/fix
  • Full Test Suite: All tests pass (0 regressions)
  • PDF Examples: Scale now matches other backends (PNG/ASCII)
  • Visual Verification: PDF plots fill plot area correctly

Files Changed

  • src/backends/vector/fortplot_pdf_coordinate.f90: Coordinate transformation fix
  • example/test_pdf_scale_regression.f90: Regression test for verification

Test Plan

  • Run regression test showing proper PDF scaling
  • Execute full test suite (all pass)
  • Generate PDF examples to verify visual scaling
  • Compare PDF vs PNG output scales (consistent)

🤖 Generated with Claude Code

## Root Cause Analysis

PDF scale regression introduced in commit 1c2fdea when aspect ratio
preservation was added to coordinate transformation functions. This caused
plots to appear smaller with centering instead of filling the plot area.

**Before**: Coordinates used independent X/Y scales, filling plot area completely
**After**: Used common scale (min of X/Y scales) for aspect ratio preservation

## Technical Fix

Restored independent axis scaling in coordinate transformation:

1. **normalize_to_pdf_coords()**: Removed common_scale, centering offsets
2. **safe_coordinate_transform()**: Removed aspect ratio preservation logic
3. **Result**: PDF plots now fill available plot area like other backends

## Changes Made

- Modified `src/backends/vector/fortplot_pdf_coordinate.f90`:
  - Removed aspect ratio preservation logic
  - Use independent x_scale and y_scale for each axis
  - Transform coordinates directly to fill plot area
  - Maintain epsilon protection for degenerate cases

## Validation

- Created regression test demonstrating issue and fix
- All tests pass with new coordinate transformation
- PDF examples generate correctly scaled output
- No impact on other backends (PNG/ASCII unaffected)

## Test Plan

- [x] Run regression test to verify fix
- [x] Run full test suite (all pass)
- [x] Generate PDF examples to verify scaling
- [x] Compare PDF output scale with PNG output (now consistent)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@krystophny krystophny merged commit aaf3e60 into main Aug 31, 2025
3 checks passed
@krystophny krystophny deleted the fix/pdf-scale-regression-985 branch August 31, 2025 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants